package gugu.services.dao.impl;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Repository;

import gugu.services.dao.CrudDao;
@Repository("crudDaoMongo")
public class CrudDaoMongoImpl<T> implements CrudDao<T> {
	private static final Log LOGGER = LogFactory.getLog(CrudDaoMongoImpl.class);
	@Resource
	private MongoOperations mongoOpts;
	@Override
	public void saveOrUpdate(T obj) {
		mongoOpts.save(obj);
		
	}
	@Override
	public boolean delete(T obj) {
		try{
			mongoOpts.remove(obj);	
		}catch(Exception e){
			LOGGER.error(e);
			return false;
		}
		
		return true;
	}
	@Override
	public T find(String id, Class<T> type) {
		return mongoOpts.findById(id, type);
	}
	@Override
	public void insert(T obj) {
		mongoOpts.insert(obj);
		
	}
}
